package com.daocao.hua.api.requestInfo;

import com.daocao.hua.api.Api;
import com.daocao.hua.api.bean.LoginBean;
import com.daocao.hua.api.callback.LoginContract;
import com.daocao.hua.util.Network;
import com.daocao.hua.util.RxLifeUtil;
import com.daocao.hua.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class LoginRequest extends BaseRequest<LoginContract.View> implements LoginContract.Presenter<LoginContract.View> {

    public static LoginRequest create() {
        return new LoginRequest();
    }


    @Override
    public void login(String account, String password) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        LoginBean bean = new LoginBean();
        bean.account = account;
        bean.password = password;
        Api.api_service.getLoginInfo(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.loginSuccess(result);
                });
    }
}
